#ifndef __LOG_INFO__
#define __LOG_INFO__
#include <my_header.h>

typedef enum {
    LOG_ERROR,
    LOG_SIGNIN,
    LOG_SIGNUP,
    LOG_OPERATION,
    LOG_DEFAULT
} LOG_TYPE;

#define LOG_INFO(LOG_FD, TYPE, FMT, ...) \
    do { \
        time_t now; \
        time(&now); \
        char time_str[20], buf[1024]; \
        struct tm *local = localtime(&now); \
        strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", local); \
        int len; \
        switch(TYPE) \
        { \
            case LOG_ERROR: \
                len = snprintf(buf, sizeof(buf), "[ERROR] [%s] " FMT, time_str, ##__VA_ARGS__); \
                break; \
            case LOG_SIGNIN: \
                len = snprintf(buf, sizeof(buf), "[SIGNIN] [%s] " FMT, time_str, ##__VA_ARGS__); \
                break; \
            case LOG_SIGNUP: \
                len = snprintf(buf, sizeof(buf), "[SIGNUP] [%s] " FMT, time_str, ##__VA_ARGS__); \
                break; \
            case LOG_OPERATION: \
                len = snprintf(buf, sizeof(buf), "[OPERATION] [%s] " FMT, time_str, ##__VA_ARGS__); \
                break; \
            default: \
                len = snprintf(buf, sizeof(buf), "[INFO] [%s] " FMT, time_str, ##__VA_ARGS__); \
                break; \
        } \
        write(LOG_FD, buf, len); \
        write(LOG_FD, "\n",1); \
    } while (0) \

#endif